package com.example.util;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 本文来演示：用于存储用户和职位点击量的类
 *
 * @author 赵建云
 * @create 2023/10/16
 */
@Component
public class JobRecommendUtils {
    private Map<Integer, Map<Integer, Float>> matrix;

    public JobRecommendUtils() {
        matrix = new HashMap<>();
    }

    public void addRating(Integer jsId, Integer productId, Float click) {
        if (!matrix.containsKey(jsId)) {
            matrix.put(jsId, new HashMap<>());
        }
        matrix.get(jsId).put(productId, click);
    }

    public Float getClick(Integer jsId, Integer productId) {
        if (matrix.containsKey(jsId)) {
            return matrix.get(jsId).get(productId);
        }
        return null;
    }

    public Map<Integer, Float> getClicks(Integer jsId) {
        if (matrix.containsKey(jsId)) {
            return matrix.get(jsId);
        }
        return new HashMap<>();
    }

    public Set<Integer> getJsIds() {
        return matrix.keySet();
    }

    public Set<Integer> getProductIds() {
        Set<Integer> productIds = new HashSet<>();
        for (Map<Integer, Float> clicks : matrix.values()) {
            productIds.addAll(clicks.keySet());
        }
        return productIds;
    }
}
